<include file="public@header" />
</head>
<style type="text/css">
    #file-wrap{
        height:34px;
        width: 82px;
        position: relative;
        display: inline-block;
        text-align: center;
        line-height: 34px;
        overflow: hidden;
        font-size: 14px;
        cursor: pointer;
        color: #fff;
        vertical-align: middle;
        background-color: #1a242f;
        border-color: #161f29;
    }
    #file-wrap input{
        position: absolute;
        height: 40px;
        z-index: 2;
        right: 0;
        top: 0;
        filter: alpha(opacity=0);
        -moz-opacity: 0;
        opacity: 0;
        cursor: pointer;
        font-size: 16px;
    }
</style>
<body>
	<div class="wrap">
		<ul class="nav nav-tabs">
            <li><a href="{:url('version/index')}">版本列表</a></li>
            <li class="active"><a href="{:url('version/add')}">新版添加</a></li>
		</ul>
		<form method="post" class="form-horizontal js-ajax-form margin-top-20" action="{:url('version/addpost')}">
			<div class="form-group">
				<label for="input-v_number" class="col-sm-2 control-label"><span class="form-required">*</span>接口版本</label>
				<div class="col-md-6 col-sm-10">
                    <input type="text" class="form-control" id="input-v_number" name="v_number" maxlength="4" value="{$version}">
				</div>
			</div>
            <div class="form-group">
                <label for="input-v_digital" class="col-sm-2 control-label"><span class="form-required">*</span>版本号</label>
                <div class="col-md-6 col-sm-10">
                    <input type="text" class="form-control" id="input-v_digital" name="v_digital" maxlength="8">
                </div>
            </div>
            <div class="form-group">
                <label for="input-v_forcibly" class="col-sm-2 control-label"><span class="form-required">*</span>强制更新</label>
                <div class="col-md-6 col-sm-10" id="input-v_forcibly">
                    <select class="form-control" name="v_forcibly">
                        <option>请选择</option>
                        <option value="10">是</option>
                        <option value="20">否</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label for="input-v_updatetime" class="col-sm-2 control-label"><span class="form-required">*</span>上线日期</label>
                <div class="col-md-6 col-sm-10">
                    <input type="datetime" class="form-control js-bootstrap-datetime" id="input-v_updatetime" name="v_updatetime" value="{:date('Y-m-d H:i',strtotime('+3 day'))}">
                </div>
            </div>
            <div class="form-group">
                <label for="input-v_description" class="col-sm-2 control-label"><span class="form-required">*</span>说明</label>
                <div class="col-md-6 col-sm-10">
                    <textarea class="form-control" id="input-v_description"  name="v_description" placeholder="发版说明"></textarea>
                </div>
            </div>
            <div class="form-group">
                <label for="input-v_type" class="col-sm-2 control-label"><span class="form-required">*</span>类型</label>
                <div class="col-md-6 col-sm-10" id="input-v_type">
                    <input type="radio" name="v_type" value="10" onclick="link()">iOS
                    <input type="radio" name="v_type" value="20" onclick="link()">Android
                </div>
            </div>
            <div class="form-group" id="android" style="display: none">
                <label for="input-file" class="col-sm-2 control-label"><span class="form-required">*</span>文件</label>
                <div class="col-md-6 col-sm-10">
                    <div id="file-wrap">
                        <input type="file" onchange="upload(this)" accept=".apk" id="input-file" name="file" style="display: inline"/>
                        选择文件
                    </div>
                    <p class="help-block">文件支持apk格式,文件大小最大不能超过32M</p>
                    <input type="button" class="btn btn-default" id="cancel_file" onclick="cancel();" value="↓↓↓取消文件↓↓↓" style="display: none">
                    <input type="hidden" name="path" id="path" value="">
                    <input type="hidden" name="file" id="file" value="">

                </div>
            </div>
            <div class="form-group">
                <label for="input-v_link" class="col-sm-2 control-label"><span class="form-required">*</span>链接</label>
                <div class="col-md-6 col-sm-10">
                    <input type="text" class="form-control" id="input-v_link" name="v_link">
                    <p class="help-block">IOS请填写App Store地址、Android文件上传后会生成地址</p>
                </div>
            </div>
			<div class="form-group">
				<div class="col-sm-offset-2 col-sm-10">
					<button type="submit" class="btn btn-primary js-ajax-submit">添加</button>
				</div>
			</div>
		</form>
	</div>
	<script src="__STATIC__/js/admin.js"></script>
	<script type="application/javascript">

        function link() {
            var intHot = $("input[name='v_type']:checked").val();
            if(intHot == 10){
                $('#android').attr('style','display: none');
            }
            if(intHot == 20){
                $('#android').attr('style','display: block');
            }
        }

        function cancel() {
            $('#file-wrap').show();
            $('#input-file').val('').attr('style','display: inline');
            $('#cancel_file').attr('style','display: none');
            $('#path').attr('value','');
            $('#file').attr('value','');
            $('#input-v_link').attr('value','');

        }

        function upload(obj) {
            var $fileinput = $(obj);
            Wind.css("jcrop");
            Wind.use("ajaxfileupload", "jcrop", "noty", function () {
                $.ajaxFileUpload({
                    url: "{:url('version/uploadfile')}",
                    secureuri: false,
                    fileElementId: "input-file",
                    dataType: 'json',
                    data: {},
                    success: function (data, status) {
                        if (data.code) {
                            $("#file-wrap").hide();
                            $('#cancel_file').show();
                            var src  = '{$simgs}'+ data.data.path + data.data.file;
                            $('#input-v_link').attr('value',src);
                            $('#path').attr('value',data.data.path);
                            $('#file').attr('value',data.data.file);
                        } else {
                            noty({
                                text: data.msg,
                                type: 'error',
                                layout: 'center',
                                callback: {
                                    afterClose: function () {
                                        reloadPage(window);
                                    }
                                }
                            });
                            cancel();
                        }
                    },
                    error: function (data, status, e) {
                        cancel();
                        alert(e + '\r文件错误。请重新选择！');
                    }
                });
            });
            return false;
        }
	</script>
</body>
</html>